﻿using DevExpress.XtraEditors.ButtonPanel;
using Marmat;
using Marmat.Forms;
using Marmat.Forms.Skin;
using Marmat.Foundation;
using Marmat.FrameWork;
using Marmat.Template.WinForm;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 测试项目.NewFolder1;
using 测试项目.TestDemo;
using MessageBox = System.Windows.Forms.MessageBox;

namespace 测试项目
{
    public partial class Form1 : System.Windows.Forms.Form, IProvider
    {
        public Form1()
        {
            InitializeComponent();
            this.testFirstDemoDataSource1.DataSource = new TestDemoEntity() { };
            this.dataGrid1.Columns.Add("A", typeof(decimal));
            this.dataGrid1.AddNew(1);
        }

        private void Form1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {

        }

        public IDocumentViewFormController<DataRow, DataTable> Controller { get; set; }


        private bool Verify(TestEntity data)
        {
            MessageBox.Show("Test");
            return false;
        }
        private bool Verify(TestEntity[] data)
        {
            MessageBox.Show("Test");
            return false;
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            var group = new Marmat.Forms.SearchControl.Group() { Name = "今日销售吨数", Domain = "1=1" };
            var field = new Marmat.Forms.SearchControl.Field() { Name = "姓名", DataType = typeof(string), Condition = "ID IN (SELECT ID FROM XXX WHERE @self)" };
            this.searchControl1.Columns.Add(group);
            this.searchControl1.Columns.Add(field);
            this.searchControl1.Columns.Add(new DataColumn("年龄", typeof(int)));
            this.searchControl1.Columns.Add(new DataColumn("出生日期", typeof(DateTime)));
            this.searchControl1.EditValue = "[{\"name\":\"今日销售吨数\"}]";

            //this.gridControl2.Columns[0].GridColumn.ColumnEdit = this.repositoryItemComboBox1;

            //this.treeView1.Nodes.Add("1");
            //this.treeView1.Nodes.Add("2");
            //var node = this.treeView1.Nodes.Add("3");
            //node.Collapse();
            //node.Nodes.Add("3.1").Nodes.Add("3.1.1");
            //node.Nodes.Add("3.2");
            //node = node.Nodes.Add("3.3");
            //node.Nodes.Add("3.3.1");
            //node.Nodes.Add("3.3.2");

            //this.treeView1.Nodes.Add("1");
            //this.treeView1.Nodes.Add("2");
            //node = this.treeView1.Nodes.Add("3");
            //node.Nodes.Add("3.1").Nodes.Add("3.1.1");
            //node.Nodes.Add("3.2");
            //node = node.Nodes.Add("3.3");
            //node.Nodes.Add("3.3.1");
            //node.Nodes.Add("3.3.2");

            //this.treeView1.ExpandAll();
        }

        private void treeView1_DrawNode(object sender, Marmat.Forms.Skin.DrawTreeNodeEventArgs e)
        {
            e.DrawDefault = true;
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            var managerForm = SystemCommand.GetService<Marmat.Foundation.IPermissionManagerForm>();
            managerForm.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var managerForm = SystemCommand.GetService<Marmat.Foundation.IDataDictionaryManagerForm>();
            managerForm.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Marmat.Template.WinForm.Alert frm = new Marmat.Template.WinForm.Alert();
            frm.Show("哈哈哈", Marmat.Foundation.AlertTypeEeum.Success);
        }
        public class UserEntity
        {
            public string UserID { get; set; }
            public string? nickName { get; set; }
        }
        private async void button4_Click(object sender, EventArgs e)
        {

            Marmat.Common.Http.FormCollection collection = new Marmat.Common.Http.FormCollection();
            collection.Files.Add(@"E:\编程开发\BI(智能控件管理方案)\BI(智能控件管理方案) 5.1\client\Marmat.Template.WinForm\bin\Debug\Marmat.Win.Template.WinForm.1.5.25.nupkg");
            string result = this.HttpApi<IUser>().Upload(collection);
        }

        private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            e.Handled = true;
            e.Graphics.DrawImage(Properties.Resources.logo, e.Bounds.Location);
        }

        private void bindingSource1_DataMemberChanged(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {
            var selection = SystemCommand.GetService<ISelectionRecordMultiForm<UserEntity>>();
            selection.Text = "选择用户";
            selection.Equals = (a, b) => a.UserID == b.UserID;
            selection.DrawCell += (sender, arg) =>
            {
                arg.DisplayText = "123";
            };
            selection.Search = (args) =>
            {
                List<UserEntity> items = new List<UserEntity>();
                foreach (var userName in new string[] { "张三", "里斯", "康佳" })
                {
                    var item = new UserEntity() { UserID = userName };
                    items.Add(item);
                }
                return items;
            };

            if (selection.ShowDialog(out var result))
            {
            }


            //List<TestDemoEntity> items = new List<TestDemoEntity>();
            //for (int i = 0; i < 10; i++)
            //{
            //    var item = new TestDemoEntity() { Name = i.ToString() };
            //    items.Add(item);
            //}
            //var selection = SystemCommand.GetService<ISelectionMultiRecordPaginationForm<TestDemoEntity>>();
            //selection.Size = new Size(1200, 800);
            //selection.DataSource = items.Skip(2).Take(4).ToArray();
            //selection.Equals = (a, b) => a.Name == b.Name;
            //selection.Columns.AddRange("Name", "Sex", "Arg");
            //selection.Search = (filter) =>
            //{
            //    List<TestDemoEntity> items = new List<TestDemoEntity>();
            //    for (int i = 0; i < 10; i++)
            //    {
            //        var item = new TestDemoEntity() { Name = i.ToString() };
            //        items.Add(item);
            //    }
            //    return items.ToArray();
            //};
            //selection.CalcItemHeight += (_, e) => e.ItemHeight = 30; ;
            //selection.DrawCell += (_, e) =>
            //{
            //    e.DisplayText = $"{e.CellValue} - txt";
            //    e.Handled = false;
            //};
            //if (selection.ShowDialog(out var result))
            //{
            //}
        }

        private void advFileView1_AddFileed(object sender, FileItem e)
        {
            e.Description = "沈雅伦 更新于 2020年12月22日 10:32";
        }


        private void gridControl1_CustomDrawColumnHeader(object sender, Marmat.Forms.Views.GridControl.ColumnHeaderCustomDrawEventArgs e)
        {
            e.Appearance.Options.UseBackColor = true;
            e.Appearance.BackColor = Color.Red;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            this.Text = this.searchControl1.Value;
        }

        private void gridControl1_CustomDrawCell(object sender, Marmat.Forms.Views.GridControl.RowCellCustomDrawEventArgs e)
        {
            if (e.Column.FieldName == "第3列")
                e.DisplayText = "11";
        }

        private void gridControl1_CellLinkClick(object sender, Marmat.Forms.Views.GridControl.RowColEventArgs e)
        {

        }

        private void gridControl1_CustomColumnDisplayText(object sender, Marmat.Forms.Views.GridControl.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column.FieldName == "第3列")
                e.DisplayText = "666";
        }

        private void tabControl3_Load(object sender, EventArgs e)
        {

        }

        private void advFileView1_CustomSaveFileing(object sender, FileManagerCustomSaveingEventArgs e)
        {

        }
    }

    public class TestEntity
    {
        public string Name { get; set; }
        public Class1<int> JJSize { get; set; }
    }
    public class TestEntity2
    {
        public string Name { get; set; }
    }

}
